#!/usr/bin/env python
# -*- coding:utf-8 -*-
import configparser
import json

from bottle import Bottle, request, response

from comm.beans.SysDictObj import SysDictObj
from conn.MyLogs import MyLogs
from excel.PruTuutDb import PruTuutDb
from hcmv.MemberWeightSeduRoute import MemberWeightSeduRoute

f = r'setting.ini'
config = configparser.RawConfigParser()
config.read(f, encoding='UTF8')

printAdm = Bottle()

mimeTypes = [
    'text/csv', 'text/plain', 'application/csv', 'text/comma-separated-values',
    'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel',
    'text/anytext', 'application/octet-stream', 'application/txt'
]

@printAdm.hook('before_request')
def validate():
    REQUEST_METHOD = request.environ.get('REQUEST_METHOD')
    HTTP_ACCESS_CONTROL_REQUEST_METHOD = request.environ.get('HTTP_ACCESS_CONTROL_REQUEST_METHOD')
    if REQUEST_METHOD == 'OPTIONS' and HTTP_ACCESS_CONTROL_REQUEST_METHOD:
        request.environ['REQUEST_METHOD'] = HTTP_ACCESS_CONTROL_REQUEST_METHOD


@printAdm.hook('after_request')
def enable_cors():
    response.headers['Access-Control-Allow-Origin'] = '*'  # 允许所有域名的请求
    response.headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PUT, HEAD, OPTIONS'
    response.headers['Access-Control-Allow-Headers'] = 'origin,content-type,accept,authorization,x-requested-with'
    response.headers["Access-Control-Allow-Credentials"] = "true"
    response.headers['Access-Control-Max-Age'] = 86400
    response.status = 200


# 微品传送门业务
class PrintInfoRoute:
    ERROR_CODE = {
        "80": "数据读取异常错误，请联系管理员",
        "99": "处理参数错误",
        "100": "数据添加失败，请检查服务端日志",
        "102": "数据更新失败，请检查服务端日志",
        "103": "数据删除失败，请检查服务端日志",
        "104": "数据停止失败，请检查服务端日志",
        "105": "数据恢复失败，请检查服务端日志",
        "106": "数据激活失败，请检查服务端日志",
        "109": "数据不存在，数据处理失败",
    }
    cfg = None
    _dict = None
    pruTuut_conn = PruTuutDb.get_pool()

    def __init__(self, cfg):
        PrintInfoRoute.cfg = cfg
        # 字典数据初始化
        PrintInfoRoute._dict = SysDictObj(PrintInfoRoute.pruTuut_conn)

    @staticmethod
    @printAdm.get('/fetch')
    def fetch():
        printId = request.params.id
        tagWidth = PrintInfoRoute._dict.load_dict_val(key_eng="tagWidth")["data"]["val"]
        tagHeight = PrintInfoRoute._dict.load_dict_val(key_eng="tagHeight")["data"]["val"]
        PrintSetting = {
            "url": "http://api.feieyun.cn/Api/Open/",
            "user": "it@vpclub.cn",
            "ukey": "mGQRyC4yICp8GGAZ",
            "sn": "570211715",
            "width": tagWidth, "height": tagHeight, "direction": "1"}
        return {'code': 200, 'data': PrintSetting, 'message': ""}

    @staticmethod
    @printAdm.get('/expMemDinner')
    def exp_mem_dinner_print():
        import datetime
        import time
        ACCESS_PRINT = PrintInfoRoute._dict.load_dict_val("ACCESS_PRINT")
        cal_day = datetime.datetime.now().strftime("%Y-%m-%d")
        res = MemberWeightSeduRoute.fetch_combination_tot(cal_date=cal_day)
        _str_split_date = None
        if res['code'] == 200:
            _str_ikk_days = res["ikk"]
            arry_ikk_days = json.loads(_str_ikk_days)
            str_print_data_index = request.params.loadIndex
            if isinstance(str_print_data_index, str):
                if str_print_data_index is not None and len(str_print_data_index)>0:
                    print_data_index = int(str_print_data_index)
                    _str_split_date = arry_ikk_days[print_data_index]
            # ----------------------------------------------------------------------- 排版设计 START
            size_bits, font_size_height, one_row_height, content_use_width, content_use_height, first_row_height = printer_init_settings(size_bits=2)
            # ----------------------------------------------------------------------- 排版设计 END
            # 判定是否指定餐食日期的需求, 按照餐食序号，打印对应的数据，否则全量打印
            if _str_split_date is not None and len(_str_split_date) > 0:
                kky = [i for i in res['data'] if i["day"] == _str_split_date]
            else:
                kky = res['data']
            print_arrys = PrintInfoRoute.exp_mem_dinner_print(kky=kky, size_bits=size_bits,
                                                                 font_size_height=font_size_height,
                                                                 first_row_height= first_row_height,
                                                                 one_row_height=one_row_height,
                                                                 content_use_width=content_use_width,
                                                                 content_use_height=content_use_height)
            send_begin_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            MyLogs.logger.info("=" * 100 + "开始推送飞鹅云打印机数据 %s" % send_begin_time)
            for ikk_idx in range(len(print_arrys)):
                ikk = print_arrys[ikk_idx]
                batch_print_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                # 推送一个批次会员数据,停留3-5秒
                # MyLogs.logger.info( "=" * 100 + f"批次打印会员数据 {mem_in_groups[ikk_idx][0]['m']} %s" % batch_print_time)
                for print_row_index in range(len(ikk)):
                    send_print_content = ikk[print_row_index]
                    MyLogs.logger.info("-" * 100 + "开始打印")
                    MyLogs.logger.info("%s: %s" % (str(print_row_index), send_print_content))
                    MyLogs.logger.info("-" * 100 + "打印结束")
                    if str(ACCESS_PRINT).upper() == "ON":
                        PrintInfoRoute.cfg.printLabelMsgWH(PrintInfoRoute.cfg.sn, send_print_content)
                    time.sleep(2)
                time.sleep(5)
            send_end_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            MyLogs.logger.info("=" * 100 + "推送飞鹅云打印机数据完成 %s" % send_end_time)
            return {'code': 200, 'data': None, 'message': ""}
        else:
            return {'code': 500, 'data': [], 'message': PrintInfoRoute.ERROR_CODE["109"]}

    @staticmethod
    def exp_mem_dinner_print(kky, size_bits, font_size_height, first_row_height, one_row_height, content_use_width,
                                content_use_height):
        from itertools import groupby
        print_arrys = []
        # 这里将数据库数据进行一次分组合并
        mem_in_groups = [list(group) for key, group in groupby(kky, key=lambda x: x['m'])]
        for mem in mem_in_groups:
            mem_print_arrys = []
            day_in_groups = [list(group) for key, group in groupby(mem, key=lambda x: x['day'])]
            for day in day_in_groups:
                dinner_in_groups = [list(group) for key, group in groupby(day, key=lambda x: x['dinner'])]
                first_row_data = dinner_in_groups[0][0]  # 首行数据内获取会员数据信息
                memID = first_row_data["mid"]
                mem_name = first_row_data["m"]
                dinner_day = first_row_data['day']
                # ----------------------------------------------------------------------- 循环拼接数据 START
                for _dinner_groups_index in range(len(dinner_in_groups)):
                    food_arrys = []
                    _food_grops = dinner_in_groups[_dinner_groups_index]
                    _stand_y_pot = {}
                    str_dinner_name = _food_grops[0]['dinner']
                    # 会员ID ------ 会员名称
                    # 年月日 ------ 早餐 / 午餐 / 晚餐
                    # 餐A ------ /克重
                    # 餐B ------ /克重
                    # 餐C ------ /克重
                    # 餐D ------ /克重
                    # 餐E ------ /克重
                    food_arrys.append(
                        f"<TEXT x='4' y='%s0' font='12' w='1' h='1' r='0'> {memID} {mem_name} {dinner_day} </TEXT>"
                    )
                    food_arrys.append(
                        f"<TEXT x='4' y='%s1' font='12' w='1' h='1' r='0'>{('-' * 3) + str_dinner_name + ('-' * 3)}</TEXT>"
                    )
                    _stand_y_pot["%s0"] = "1" # 3mm = 3*8dot = 24
                    _stand_y_pot["%s1"] = str(1*24+8) # 5mm = top 1mm*8dot + 3mm*8dot + buttom 1mm*8dot= 40
                    # 标签内数据行数
                    _print_data_ary = [{"name": i["food"], "kgs": i["kgs"]} for i in _food_grops]
                    _begin_idx_y = 64
                    _tmp_ary = [i for i in range(_begin_idx_y, content_use_height, font_size_height)]
                    for val_idx in range(len(_tmp_ary)):
                        _stand_y_pot["%s" + str(val_idx + 2)] = str(_tmp_ary[val_idx])
                    for idx in range(len(_print_data_ary)):
                        x0 = 4
                        food_arrys.append(
                            f"<TEXT x='{x0}' y='%s{idx + 2}' font='12' w='{size_bits}' h='{size_bits}' r='0'>{_print_data_ary[idx]['name']}</TEXT>")
                        x1 = cal_str_pot(obj=_print_data_ary[idx], paper_size_w=content_use_width, size_bits=size_bits)
                        food_arrys.append(
                            f"<TEXT x='{x1}' y='%s{idx + 2}' font='12' w='{size_bits}' h='{size_bits}' r='0'>{int(_print_data_ary[idx]['kgs'])}</TEXT>"
                        )
                    content = "".join(food_arrys)
                    for key, val in _stand_y_pot.items():
                        content = content.replace(key, val)
                    res = PrintInfoRoute._dict.load_dict_val(key_eng="custPrintCount")
                    custPrintCount = json.loads(res['data']['val'])
                    for i in range(int(custPrintCount)):
                        mem_print_arrys.append(content)
            print_arrys.append(mem_print_arrys)
        return print_arrys
    @staticmethod
    def exp_mem_dinner_print_80(kky, size_bits, font_size_height, first_row_height, one_row_height, content_use_width,
                                content_use_height):
        from itertools import groupby
        print_arrys = []
        # 这里将数据库数据进行一次分组合并
        mem_in_groups = [list(group) for key, group in groupby(kky, key=lambda x: x['m'])]
        for mem in mem_in_groups:
            mem_print_arrys = []
            day_in_groups = [list(group) for key, group in groupby(mem, key=lambda x: x['day'])]
            for day in day_in_groups:
                dinner_in_groups = [list(group) for key, group in groupby(day, key=lambda x: x['dinner'])]
                first_row_data = dinner_in_groups[0][0]  # 首行数据内获取会员数据信息
                memID = first_row_data["mid"]
                mem_name = first_row_data["m"]
                dinner_day = first_row_data['day']
                # ----------------------------------------------------------------------- 循环拼接数据 START
                for _dinner_groups_index in range(len(dinner_in_groups)):
                    food_arrys = []
                    _food_grops = dinner_in_groups[_dinner_groups_index]
                    _stand_y_pot = {}
                    str_dinner_name = _food_grops[0]['dinner']
                    # 会员ID ------ 会员名称
                    # 年月日 ------ 早餐 / 午餐 / 晚餐
                    # 餐A ------ /克重
                    # 餐B ------ /克重
                    # 餐C ------ /克重
                    # 餐D ------ /克重
                    # 餐E ------ /克重
                    # ---------------
                    # QECODE STR / ERCODE
                    food_arrys.append(
                        f"<TEXT x='16' y='%s0' font='12' w='{size_bits}' h='{size_bits}' r='0'>{memID} {mem_name}</TEXT>"
                    )
                    food_arrys.append(
                        f"<TEXT x='16' y='%s1' font='12' w='{size_bits}' h='{size_bits}' r='0'>{dinner_day} {str_dinner_name}</TEXT>"
                    )
                    # 数据处理
                    _print_data_ary = [{"name": i["food"], "kgs": i["kgs"]} for i in _food_grops]
                    # 坐标处理
                    _ary_content_height_points = [i for i in range(0, content_use_height, one_row_height)][2:] # start ,end ,step
                    _stand_y_pot["%s0"] = str(0)
                    _stand_y_pot["%s1"] = str(one_row_height)
                    for val_idx in range(len(_ary_content_height_points)):
                        _stand_y_pot["%s" + str(val_idx+2)] = str(_ary_content_height_points[val_idx])
                    for idx in range(len(_print_data_ary)):
                        # 食材名称
                        x0 = 16
                        food_arrys.append(
                            f"<TEXT x='{x0}' y='%s{idx + 2}' font='12' w='{size_bits}' h='{size_bits}' r='0'>{_print_data_ary[idx]['name']}</TEXT>")
                        x1 = cal_str_pot(obj=_print_data_ary[idx], paper_size_w=content_use_width, size_bits=size_bits)
                        food_arrys.append(
                            f"<TEXT x='{x1}' y='%s{idx + 2}' font='12' w='{size_bits}' h='{size_bits}' r='0'>{int(_print_data_ary[idx]['kgs'])}</TEXT>"
                        )
                    _split_y_points = _ary_content_height_points[len(_print_data_ary)]-8
                    food_arrys.append(
                        f"<TEXT x='8' y='{_split_y_points}' font='1' w='1' h='1' r='0'>{('-'*40)}</TEXT>"
                    )
                    QR_CODE_X = 20
                    QR_CODE_Y = _split_y_points+16
                    food_arrys.append(
                        f"<QR x='{QR_CODE_X}' y='{QR_CODE_Y}' e='L' w='6'>http://www.baidu.com</QR>"
                    )
                    QR_CODE_STR_X = 20 * 8 + 24
                    food_arrys.append(
                        f"<TEXT x='{QR_CODE_STR_X}' y='{QR_CODE_Y}' font='12' w='1' h='1' r='0'>http://www.baidu.com</TEXT>"
                    )
                    ER_CODE_STR_Y = QR_CODE_Y + 24
                    food_arrys.append(
                        f"<BC39 x='{QR_CODE_STR_X}' y='%s{ER_CODE_STR_Y}' h='40' s='1' r='0' n='2' w='1'>{memID}</BC39>"
                    )
                    content = "".join(food_arrys)
                    for key, val in _stand_y_pot.items():
                        content = content.replace(key, val)
                    res = PrintInfoRoute._dict.load_dict_val(key_eng="custPrintCount")
                    custPrintCount = json.loads(res['data']['val'])
                    for i in range(int(custPrintCount)):
                        mem_print_arrys.append(content)
            print_arrys.append(mem_print_arrys)
        return print_arrys

    @staticmethod
    @printAdm.post('/supplyPrinting')
    def exp_mem_dinner_excel():
        from dateutil.parser import isoparse
        import datetime
        if request.json is not None:
            try:
                data = request.json['data']
                # 替换日期
                dinner_day = data["printDay"]
                print_range_day = data["printDayRange"]
                # 会员数据
                str_supply_mem_json = data["printMemData"]
                int_dayIdx = int(data["dayIdx"]) - 1
                if dinner_day is not None and len(dinner_day)>0:
                    dt_obj = isoparse(dinner_day)
                    _str_formatted_dinner_day = dt_obj.strftime('%Y-%m-%d')
                    PrintInfoRoute.print_with_data(dayIdx= int_dayIdx, str_supply_mem_json = str_supply_mem_json, _str_formatted_dinner_day=_str_formatted_dinner_day)
                else:
                    begin = print_range_day[0]
                    dt_begin_obj = isoparse(begin)
                    end = print_range_day[1]
                    dt_end_obj = isoparse(end)
                    delta = (dt_end_obj-dt_begin_obj).days
                    for idx in range(delta):
                        _str_formatted_dinner_day = (dt_begin_obj + datetime.timedelta(days=+idx)).strftime("%Y-%m-%d")
                        PrintInfoRoute.print_with_data(dayIdx=int_dayIdx + idx, str_supply_mem_json=str_supply_mem_json,
                                                       _str_formatted_dinner_day=_str_formatted_dinner_day)
                return {'code': 200, 'data': None, 'message': ""}
            except Exception as e:
                return {'code': 500, 'data': [], 'message': PrintInfoRoute.ERROR_CODE["109"]}
    @staticmethod
    @printAdm.post('/setPrinter')
    def set_printer_info():
        if request.json is not None:
            try:
                data = request.json['data']
                PrintInfoRoute._dict.set_dict_val(key_eng="tagWidth", val=data['width'])
                PrintInfoRoute._dict.set_dict_val(key_eng="tagHeight", val=data['height'])
                setting_info = {"width": data['width'], "height": data['height']}
                PrintInfoRoute.cfg.setPrinterWidth(setting=setting_info, sn=PrintInfoRoute.cfg.sn)
                return {'code': 200, 'data': None, 'message': ""}
            except Exception as e:
                return {'code': 500, 'data': [], 'message': PrintInfoRoute.ERROR_CODE["109"]}

    @staticmethod
    def print_with_data(dayIdx: int, str_supply_mem_json: str, _str_formatted_dinner_day: str):
        import datetime
        import time
        from hcmv.MemberWeightService import MemeberWeightService
        from hcmv.WeightLossPlanService import WeightLossPlanService
        ACCESS_PRINT = PrintInfoRoute._dict.load_dict_val("ACCESS_PRINT")["data"]["val"]
        weightLossPlanService = WeightLossPlanService(PrintInfoRoute.pruTuut_conn)
        memberWeightService = MemeberWeightService(PrintInfoRoute.pruTuut_conn)
        # 餐食索引获取餐食数据
        _choose_cust_dinner_switch = PrintInfoRoute._dict.load_dict_val("custDinnerSw")["data"]["val"]
        if str(_choose_cust_dinner_switch).upper() == 'ON':
            view_list = MemberWeightSeduRoute.custom_choose_dinner_data()
        else:
            view_list = []
        # one_day_dinner_data = view_list[int(data["dayIdx"]) - 1]["list"]
        one_day_dinner_data = view_list[dayIdx]["list"]
        # ------------------------------------------------------------------------------------------------------
        ary_supply_mem = json.loads(str_supply_mem_json)
        print_mems = []
        for member in ary_supply_mem:
            cal_member_heat_data = memberWeightService.cal_member_weight(view=None, memberId=member["member_id"])["data"]
            cal_member_heat_data["name"] = member["name"]
            cal_member_heat_data["member_sno"] = member["member_sno"]
            one_day_dinners = MemberWeightSeduRoute.make_one_day_dinner_in_ary(one_day_dinner_data, cal_member_heat_data)
            # 根据会员摄入的食材数据，从数据库中计算餐食食材的对应摄入克重，维生素类食材不在热量计算范围内，使用1作为数据量替换，同类食材平均分配摄入重量
            if int(cal_member_heat_data["sex"]) == 0:
                dinner_std_weight = PrintInfoRoute._dict.load_dict_val(key_eng="mDinnerStdKgs")["data"]["val"]
            elif int(cal_member_heat_data["sex"]) == 1:
                dinner_std_weight = PrintInfoRoute._dict.load_dict_val(key_eng="fDinnerStdKgs")["data"]["val"]
            _str_VitaminProportion = PrintInfoRoute._dict.load_dict_val(key_eng="VitaminProportion")["data"]["val"]
            member_dinners = weightLossPlanService.calculation_ingredient_ratio_with_dinner(
                dinners=one_day_dinners,
                dinnerStdWeight=dinner_std_weight,
                vitaminProportion=float(_str_VitaminProportion))
            print_mems.append({"member": cal_member_heat_data, "member_dinners": member_dinners["data"]["ARRY"]})
        # ------------------------------------------------------------------------------------------------------
        # ----------------------------------------------------------------------- 排版设计 START
        size_bits, font_size_height, one_row_height, content_use_width, content_use_height, first_row_height = printer_init_settings(
            size_bits=2)
        # ----------------------------------------------------------------------- 排版设计 END
        print_arrys = []
        for mem_idx in range(len(print_mems)):
            _obj_mem = print_mems[mem_idx]
            memID = _obj_mem["member"]["member_sno"]
            mem_name = _obj_mem["member"]["name"]
            # ----------------------------------------------------------------------- 循环拼接数据 START
            # 餐打印
            print_times = []
            for _dinner_index in range(len(_obj_mem["member_dinners"])):
                # 食材打印
                for key, val in _obj_mem["member_dinners"][_dinner_index].items():
                    _can_content_arrys = []
                    _stand_y_pot = {}
                    str_dinner_name = MemberWeightSeduRoute.dict_dinner_names[key]
                    _can_content_arrys.append(
                        f"<TEXT x='10' y='%s0' font='12' w='1' h='1' r='0'>-{memID}---{mem_name} {_str_formatted_dinner_day}</TEXT>")
                    _stand_y_pot["%s0"] = "1"
                    _obj_dinner = val
                    # 标签内数据行数 = 3 +
                    content_rows_height = (3 + len(_obj_dinner)) * (font_size_height + 8)  # 预留每行1MM空位
                    content_use_height = content_use_height if content_rows_height > content_use_height else content_rows_height
                    _print_data_ary = [{"name": i["name"], "kgs": i["intake"]} for i in _obj_dinner]
                    _can_content_arrys.append(
                        f"<TEXT x='4' y='%s1' font='12' w='1' h='1' r='0'>{'-' * 3 + str_dinner_name + '-' * 9}</TEXT>")
                    _stand_y_pot["%s1"] = str(str(1 * 24 + 8))
                    _tmp_ary = [i for i in range(64, content_use_height, font_size_height)]  # 根据字体计算确认每一行内容Y轴高度
                    for val_idx in range(len(_tmp_ary)):
                        _stand_y_pot["%s" + str(val_idx + 2)] = str(_tmp_ary[val_idx])  # 0，1 索引被占用，从下标开始计算索引
                    for idx in range(len(_print_data_ary)):
                        _can_content_arrys.append(
                            f"<TEXT x='4' y='%s{idx + 2}' font='12' w='{size_bits}' h='{size_bits}' r='0'>{_print_data_ary[idx]['name']}</TEXT>")  # 餐名
                        x1 = cal_str_pot(_print_data_ary[idx], paper_size_w=content_use_width, size_bits=size_bits)
                        _can_content_arrys.append(
                            f"<TEXT x='{x1}' y='%s{idx + 2}' font='12' w='{size_bits}' h='{size_bits}' r='0'>{int(_print_data_ary[idx]['kgs'])}</TEXT>")  # 克重
                    _can_content = "".join(_can_content_arrys)
                    for key, val in _stand_y_pot.items():
                        _can_content = _can_content.replace(key, val)
                    # 根据新的数据标签样本 会员 A,B,C,D 其中 餐食 AA,BB,CC,食材顺序不变
                    res = PrintInfoRoute._dict.load_dict_val(key_eng="custPrintCount")
                    custPrintCount = json.loads(res['data']['val'])
                    for i in range(int(custPrintCount)):
                        print_times.append(_can_content)
            print_arrys.append({"mem_name": mem_name, "ikk": print_times})
            # ----------------------------------------------------------------------- 循环拼接数据 END
        # 按照补充会员信息，打印数据
        send_begin_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        MyLogs.logger.info("=" * 100 + "开始推送飞鹅云打印机数据 %s" % send_begin_time)
        for _xun in print_arrys:
            batch_print_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            MyLogs.logger.info("=" * 100 + f"批次打印会员数据 {_xun['mem_name']} %s" % batch_print_time)
            for ikk_idx in range(len(_xun["ikk"])):
                send_print_content = _xun["ikk"][ikk_idx]
                MyLogs.logger.info("-" * 100 + "开始打印")
                MyLogs.logger.info("%s: %s" % (str(ikk_idx), send_print_content))
                MyLogs.logger.info("-" * 100 + "打印结束")
                if str(ACCESS_PRINT).upper() == "ON":
                    PrintInfoRoute.cfg.printLabelMsgWH(PrintInfoRoute.cfg.sn, send_print_content)
                time.sleep(2)
            # 推送一个批次会员数据,停留3-5秒
            time.sleep(5)
        send_end_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        MyLogs.logger.info("=" * 100 + "推送飞鹅云打印机数据完成 %s" % send_end_time)

def cal_str_pot(obj, paper_size_w, size_bits):
    _len_c = len(str(obj["name"])) * (24 * size_bits)
    _len_e = len(str(obj["kgs"])) * (12 * size_bits)
    if _len_c > paper_size_w / 2:
        # return _len_c + 48
        return 270 + 48
    else:
        # return int(paper_size_w / 2)
        return 270 + 48


# size_bits 字体放大倍数
def printer_init_settings(size_bits):
    tagWidth = PrintInfoRoute._dict.load_dict_val(key_eng="tagWidth")["data"]["val"]
    tagHeight = PrintInfoRoute._dict.load_dict_val(key_eng="tagHeight")["data"]["val"]
    split_padding = 4  # 行间距,用点阵替换 8点阵 = 1mm
    # x，y值需要按照实际使用的纸规格大小取值。例如标签纸大小为：宽40mm，高度为30mm。
    # 1mm = 8dots
    tot_height = 8 * int(tagHeight)  # 标签纸张总高度，单位点阵
    tot_width = 8 * int(tagWidth)  # 标签纸张总宽度，单位点阵
    # 12、 简体中文 24×24Font(GB 码)
    font_size_height = (24 * size_bits)  # 单位点阵 12 号字体,24DOT * 24DOT = 5 MM
    one_row_height = split_padding + (font_size_height) + split_padding
    first_row_height = split_padding * 1
    content_use_height = tot_height - (split_padding * 0) - (split_padding * 0)  # 留出上下各1mm空余
    content_use_width = tot_width - (split_padding * 0) - (split_padding * 0)  # 留出左右各2mm空余
    return size_bits, font_size_height, one_row_height, content_use_width, content_use_height, first_row_height
